<!-- 经销商 -->
<template>
   <div class="app-container">
      <el-form label-width="100px" :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
         <el-form-item label="经销商编号" prop="code">
            <el-input v-model="queryParams.code" placeholder="请输入经销商编号" clearable style="width: 240px"
               @keyup.enter.native="handleQuery" />
         </el-form-item>
         <el-form-item label="经销商名称" prop="name">
            <el-input v-model="queryParams.name" placeholder="请输入经销商名称" clearable style="width: 240px"
               @keyup.enter.native="handleQuery" />
         </el-form-item>
         <!-- <el-form-item label="经销商编号" prop="disCode">
        <el-input
          v-model="queryParams.disCode"
          placeholder="请输入经销商编号"
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
         <el-form-item label="绑定系统" prop="target">
            <el-select v-model="queryParams.target" placeholder="绑定系统" clearable style="width: 240px">
               <el-option v-for="dict in dict.type.integra_system" :key="dict.value" :label="dict.label"
                  :value="dict.value" />
            </el-select>
         </el-form-item>
         <el-form-item label="绑定状态" prop="bindStatus">
            <el-select v-model="queryParams.bindStatus" placeholder="绑定状态" clearable style="width: 240px">
               <el-option v-for="dict in bindStatus" :key="dict.value" :label="dict.label" :value="dict.value" />
            </el-select>
         </el-form-item>
         <el-form-item label="状态" prop="status">
            <el-select v-model="queryParams.status" placeholder="状态" clearable style="width: 240px">
               <el-option v-for="dict in dict.type.data_status" :key="dict.value" :label="dict.label"
                  :value="dict.value" />
            </el-select>
         </el-form-item>
         <el-form-item label="创建时间">
            <el-date-picker v-model="dateRange" style="width: 340px" value-format="yyyy-MM-dd HH:mm:ss"
               type="datetimerange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"
               :default-time="['00:00:00', '23:59:59']"></el-date-picker>
         </el-form-item>
         <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
         </el-form-item>
      </el-form>

      <el-row :gutter="10" class="mb8">
      <!-- <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:role:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:role:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:role:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:role:export']"
        >导出</el-button>
      </el-col> -->
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          size="mini"
          @click="synchronismData"
          v-hasPermi="['system:role:export']"
        >数据同步</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

      <el-table border v-loading="loading" :data="roleList" @selection-change="handleSelectionChange">
         <el-table-column type="selection" width="55" fixed align="center" />
         <el-table-column label="序号" type="index" width="55" fixed align="center" />
         <el-table-column label="经销商编号" prop="code" width="200" />
         <el-table-column label="经销商名称" prop="name" width="200" />
         <el-table-column label="渠道类型" prop="channelType" width="120">
            <!-- 0经销商、1工程、2直营 -->
            <template slot-scope="scope">
               <span v-if="scope.row.channelType == 0">经销商</span>
               <span v-else-if="scope.row.channelType == 1">工程</span>
               <span v-else-if="scope.row.channelType == 2">直营</span>
            </template>
         </el-table-column>
         <el-table-column label="区域" prop="region" width="200" />
         <el-table-column label="联系人" prop="linkman" width="200" />
         <el-table-column label="联系地址" prop="linkAddress" width="200" />
         <el-table-column label="经销商等级" prop="level" width="200" />
         <el-table-column label="货币类型" prop="currencyType" width="200" />
         <el-table-column label="价格码" prop="priceCode" width="200" />
         <el-table-column label="绑定系统" prop="target" width="200" >
            <template slot-scope="scope">
              <dict-tag :options="dict.type.integra_system" :value="scope.row.target"/>
            </template>
            
         </el-table-column>
         <el-table-column label="绑定状态" prop="bindStatus" width="120">
            <template slot-scope="scope">
               <span v-if="scope.row.bindStatus == 0">未绑定</span>
               <span v-else-if="scope.row.bindStatus == 1">已绑定</span>
            </template>
         </el-table-column>
         <el-table-column label="绑定时间" prop="bindTime" width="200" />
         <el-table-column label="经销商类型" prop="type" width="120">
            <template slot-scope="scope">
               <span v-if="scope.row.status == 1">分拨</span>
               <span v-else-if="scope.row.status == 2">一批</span>
               <span v-else-if="scope.row.status == 3">二批</span>
            </template>
         </el-table-column>
         <el-table-column label="配置客户编号" prop="configCustomerCode" width="200" />
         <el-table-column label="配置客户名称" prop="configCustomerName" width="200" />
         <!-- <el-table-column label="unitVoList" prop="unitVoList"    width="120"/> -->
         <!-- <el-table-column label="显示顺序" prop="roleSort" width="100" /> -->
         <el-table-column label="状态" align="center" width="120">
            <template slot-scope="scope">
               <span v-if="scope.row.status == 0">停用</span>
               <span v-else-if="scope.row.status == 1">启用</span>
            </template>
         </el-table-column>
         <el-table-column label="同步状态" align="center" width="120">
            <template slot-scope="scope">
               <span v-if="scope.row.syncStatus == -0">未同步</span>
               <span v-if="scope.row.syncStatus == 0">同步失败</span>
               <span v-else-if="scope.row.syncStatus == 1">同步成功</span>
               <span v-else-if="scope.row.syncStatus == 2">无需成功</span>
            </template>
         </el-table-column>
         <el-table-column label="错误描述" prop="syncDesc" width="200" />
         <el-table-column prop="createTime" label="创建时间" width="180"> </el-table-column>
         <el-table-column prop="updateTime" label="修改时间" width="180"> </el-table-column>
         
         <!-- <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column> -->
         <el-table-column label="操作" width="200" fixed="right" align="center" class-name="small-padding fixed-width">
            <template slot-scope="scope">
               <el-button size="mini" type="text" @click="virtualCustomer(scope.row)">收货地址</el-button>
               <el-button size="mini" type="text" @click="handleUpdate(scope.row)">任意接配置</el-button>
               <el-button size="mini" type="text" @click="handleDelete(scope.row)">配置</el-button>
            </template>
         </el-table-column>
      </el-table>

      <pagination v-show="total > 0" :total="total" :page.sync="queryParams.current" :limit.sync="queryParams.size"
         @pagination="getList" />

      <!-- 添加或修改角色配置对话框 -->
      <el-dialog :title="title" :visible.sync="open" width="70%" append-to-body>
         <el-form ref="form" :model="form" :rules="rules" label-width="130px" :inline="true">
            <el-form-item label="经销商编号" prop="disCode">
               <el-input style="width: 240px" v-model="form.disCode" disabled />
            </el-form-item>
            <el-form-item required label="接口地址" prop="url">
               <el-input clearable style="width: 240px" v-model="form.url" placeholder="请输入接口地址" />
            </el-form-item>
            <el-form-item required label="公司名称" prop="companyName">
               <el-input clearable style="width: 240px" v-model="form.companyName" placeholder="请输入公司名称" />
            </el-form-item>
            <el-form-item required label="方案名称" prop="schemeName">
               <el-input clearable style="width: 240px" v-model="form.schemeName" placeholder="请输入方案名称" />
            </el-form-item>
            <el-form-item required label="数据库链接" prop="dbLink">
               <el-input clearable style="width: 240px" v-model="form.dbLink" placeholder="请输入数据库链接" />
            </el-form-item>
            <el-form-item required label="数据库用户名" prop="dbUser">
               <el-input clearable style="width: 240px" v-model="form.dbUser" placeholder="请输入数据库用户名" />
            </el-form-item>
            <el-form-item required label="数据库密码" prop="dbPwd">
               <el-input type="password" show-password clearable style="width: 240px" v-model="form.dbPwd"
                  placeholder="请输入数据库密码" />
            </el-form-item>
            <el-form-item required label="数据库名称" prop="dbName">
               <el-input clearable style="width: 240px" v-model="form.dbName" placeholder="请输入数据库名称" />
            </el-form-item>
            <el-form-item label="数据库账号" prop="dbAccount">
               <el-input clearable style="width: 240px" v-model="form.dbAccount" placeholder="请输入数据库账号" />
            </el-form-item>
            <el-form-item label="财贸API" prop="apiLink">
               <el-input clearable style="width: 240px" v-model="form.apiLink" placeholder="请输入财贸API" />
            </el-form-item>
            <el-form-item label="财贸API KEY" prop="apiSecret">
               <el-input clearable style="width: 240px" v-model="form.apiSecret" placeholder="请输入财贸API KEY" />
            </el-form-item>
            <el-form-item required label="产品类型" prop="productType">
               <!-- <el-input clearable style="width: 240px" v-model="form.productType" placeholder="请输入产品类型" /> -->
               <el-select v-model="form.productType" placeholder="请选择角色状态" clearable style="width: 240px">
                  <el-option v-for="dict in dict.type.product_type" :key="dict.value" :label="dict.label"
                     :value="dict.value" />
               </el-select>
            </el-form-item>
            <el-form-item label="自定义1" prop="custom1">
               <el-input clearable style="width: 240px" v-model="form.custom1" placeholder="请输入自定义1" />
            </el-form-item>
            <el-form-item label="自定义2" prop="custom2">
               <el-input clearable style="width: 240px" v-model="form.custom2" placeholder="请输入自定义2" />
            </el-form-item>
            <el-form-item label="API版本" prop="apiVersion">
               <el-input clearable style="width: 240px" v-model="form.apiVersion" placeholder="请输入API版本" />
            </el-form-item>
            <el-form-item required label="是否开启对照" prop="isComparison">
               <el-select clearable v-model="form.isComparison" placeholder="请选择是否开启对照" style="width: 240px">
                  <el-option v-for="dict in dict.type.is_comparison" :key="dict.value" :label="dict.label"
                     :value="dict.value" />
               </el-select>
            </el-form-item>
         </el-form>
         <div slot="footer" class="dialog-footer">
            <el-button type="primary" @click="submitForm">确 定</el-button>
            <el-button @click="cancel">取 消</el-button>
         </div>
      </el-dialog>

      <el-dialog title="经销商配置" :visible.sync="showConfig" width="70%">
         <el-table :data="resData" style="width: 100%">
            <el-table-column prop="systemCode" label="系统编号" width="180"> </el-table-column>
            <el-table-column prop="url" label="接口地址" width="320"> </el-table-column>
            <el-table-column prop="dbName" label="数据库名称" width="180"> </el-table-column>
            <el-table-column prop="schemeId" label="方案ID" width="180"> </el-table-column>
            <el-table-column prop="status" label="状态" width="180"> </el-table-column>
            <el-table-column prop="createTime" label="创建时间" width="180"> </el-table-column>
            <el-table-column prop="updateTime" label="修改时间" width="180"> </el-table-column>

         </el-table>
      </el-dialog>
      <el-dialog title="收货地址" :visible.sync="virtual_customer" width="70vw" append-to-body>
         <el-form label-width="100px" :model="virtual_customer_list" ref="virtual_customer_queryForm" size="small" :inline="true" >
            <el-form-item label="收货地址编号" prop="code">
               <el-input v-model="virtual_customer_list.code" placeholder="请输入收货地址编号" clearable style="width: 240px"
                  @keyup.enter.native="set_virtual_customer" />
            </el-form-item>
            <el-form-item label="收货人" prop="consignee">
               <el-input v-model="virtual_customer_list.consignee" placeholder="请输入收货人" clearable style="width: 240px"
                  @keyup.enter.native="set_virtual_customer" />
            </el-form-item>
            <el-form-item>
               <el-button type="primary" icon="el-icon-search" size="mini" @click="set_virtual_customer">搜索</el-button>
               <el-button icon="el-icon-refresh" size="mini" @click="shipping_addressresetQuery">重置</el-button>
            </el-form-item>
         </el-form>
         <el-table :data="shipping_address_data" style="width: 100%" height="60vh">
            <el-table-column type="index" label="序号" width="80"> </el-table-column>
            <el-table-column prop="code" label="编号" width="180" show-overflow-tooltip> </el-table-column>
            <el-table-column prop="name" label="名称" width="240" show-overflow-tooltip> </el-table-column>
            <el-table-column prop="consignee" label="收货人" width="120"> </el-table-column>
            <el-table-column prop="consigneeAddress" label="收货地址" width="280" show-overflow-tooltip> </el-table-column>
            <el-table-column prop="consigneeTel" label="收货联系方式" width="200" show-overflow-tooltip> </el-table-column>
            <el-table-column prop="createTime" label="创建时间" width="180"> </el-table-column>
            <el-table-column prop="updateTime" label="修改时间" width="180"> </el-table-column>

         </el-table>
         

         <pagination v-show="shipping_address_total > 0" :total="shipping_address_total" :page.sync="virtual_customer_list.current" :limit.sync="virtual_customer_list.size"
         @pagination="set_virtual_customer" />
      </el-dialog>
      <!-- 分配角色数据权限对话框 -->
      <el-dialog :title="title" :visible.sync="openDataScope" width="500px" append-to-body>
         <el-form :model="form" label-width="80px">
            <el-form-item label="角色名称">
               <el-input v-model="form.code" :disabled="true" />
            </el-form-item>
            <el-form-item label="权限字符">
               <el-input v-model="form.name" :disabled="true" />
            </el-form-item>
            <el-form-item label="权限范围">
               <el-select v-model="form.dataScope" @change="dataScopeSelectChange">
                  <el-option v-for="item in dataScopeOptions" :key="item.value" :label="item.label"
                     :value="item.value"></el-option>
               </el-select>
            </el-form-item>
            <el-form-item label="数据权限" v-show="form.dataScope == 2">
               <el-checkbox v-model="deptExpand" @change="handleCheckedTreeExpand($event, 'dept')">展开/折叠</el-checkbox>
               <el-checkbox v-model="deptNodeAll"
                  @change="handleCheckedTreeNodeAll($event, 'dept')">全选/全不选</el-checkbox>
               <el-checkbox v-model="form.deptCheckStrictly"
                  @change="handleCheckedTreeConnect($event, 'dept')">父子联动</el-checkbox>
               <el-tree class="tree-border" :data="deptOptions" show-checkbox default-expand-all ref="dept"
                  node-key="id" :check-strictly="!form.deptCheckStrictly" empty-text="加载中，请稍候"
                  :props="defaultProps"></el-tree>
            </el-form-item>
         </el-form>
         <div slot="footer" class="dialog-footer">
            <el-button type="primary" @click="submitDataScope">确 定</el-button>
            <el-button @click="cancelDataScope">取 消</el-button>
         </div>
      </el-dialog>
   </div>
</template>

<script>
import { listRole, getRole, delRole, addRole, updateRole, dataScope, changeRoleStatus, deptTreeSelect } from "@/api/system/role";
import {
   hqDisPage,
   hqDisSchemeConfigSaveOrUpdate,
   hqDisConfigList,
   hqDisAddressPage,
   hqDisIssue
} from "@/api/base/dis";

import { treeselect as menuTreeselect, roleMenuTreeselect } from "@/api/system/menu";

export default {
   name: "Role",
   dicts: ['data_status', 'product_type', 'is_comparison', 'integra_system'],
   data() {
      return {
         // 遮罩层
         loading: true,
         // 选中数组
         ids: [],
         // 非单个禁用
         single: true,
         // 非多个禁用
         multiple: true,
         // 显示搜索条件
         showSearch: true,
         // 总条数
         total: 0,
         shipping_address_total: 0,
         // 角色表格数据
         roleList: [],
         // 弹出层标题
         title: "",
         // 是否显示弹出层
         open: false,
         // 是否显示弹出层（数据权限）
         openDataScope: false,
         menuExpand: false,
         menuNodeAll: false,
         deptExpand: true,
         deptNodeAll: false,
         // 日期范围
         dateRange: [],
         // 数据范围选项
         dataScopeOptions: [
            {
               value: "1",
               label: "全部数据权限"
            },
            {
               value: "2",
               label: "自定数据权限"
            },
            {
               value: "3",
               label: "本部门数据权限"
            },
            {
               value: "4",
               label: "本部门及以下数据权限"
            },
            {
               value: "5",
               label: "仅本人数据权限"
            }
         ],
         // 菜单列表
         menuOptions: [],
         // 部门列表
         deptOptions: [],
         // 查询参数
         queryParams: {
            current: 1,
            size: 10,
            code: undefined,
            name: undefined,
            target: undefined,
            bindStatus: undefined,
            status: undefined,
            startTime: undefined,
            endTime: undefined,
         },
         // 表单参数
         form: {},
         defaultProps: {
            children: "children",
            label: "label"
         },
         // 表单校验
         rules: {
            url: [
               { required: true, message: "接口地址不能为空", trigger: "blur" }
            ],
            companyName: [
               { required: true, message: "公司名称不能为空", trigger: "blur" }
            ],
            schemeName: [
               { required: true, message: "方案名称不能为空", trigger: "blur" }
            ],
            dbLink: [
               { required: true, message: "数据库链接不能为空", trigger: "blur" }
            ],
            dbUser: [
               { required: true, message: "数据库用户名不能为空", trigger: "blur" }
            ],
            dbPwd: [
               { required: true, message: "数据库密码不能为空", trigger: "blur" }
            ],
            dbName: [
               { required: true, message: "数据库名称不能为空", trigger: "blur" }
            ],
            isComparison: [
               { required: true, message: "是否开启对照不能为空", trigger: "change" }
            ],
            productType: [
               { required: true, message: "产品类型不能为空", trigger: "change" }
            ],
         },
         showConfig: false,
         resData: [],
         virtual_customer: false,
         virtual_customer_data: '',
         virtual_customer_list: {
            current: 1,
            size: 10,
            disId: '',
            code: '',
            consignee: '',
         },
         bindStatus: [{
            value: 0,
            label: '未绑定'
         }, {
            value: 1,
            label: '已绑定'
         }],
         shipping_address_data: [],
      };
   },
   created() {
      this.getList();
   },
   methods: {
      /** 查询角色列表 */
      getList() {
         this.loading = true;
         // addRole(this.form).then(response => {})
         hqDisPage(this.addDateRange2(this.queryParams, this.dateRange, ['startTime', 'endTime'])).then(response => {
            console.log('list', response);
            this.roleList = response.data.records;
            this.total = response.data.total;
            this.loading = false;
         });
      },
      /** 查询菜单树结构 */
      getMenuTreeselect() {
         menuTreeselect().then(response => {
            this.menuOptions = response.data;
         });
      },
      // 所有菜单节点数据
      getMenuAllCheckedKeys() {
         // 目前被选中的菜单节点
         let checkedKeys = this.$refs.menu.getCheckedKeys();
         // 半选中的菜单节点
         let halfCheckedKeys = this.$refs.menu.getHalfCheckedKeys();
         checkedKeys.unshift.apply(checkedKeys, halfCheckedKeys);
         return checkedKeys;
      },
      // 所有部门节点数据
      getDeptAllCheckedKeys() {
         // 目前被选中的部门节点
         let checkedKeys = this.$refs.dept.getCheckedKeys();
         // 半选中的部门节点
         let halfCheckedKeys = this.$refs.dept.getHalfCheckedKeys();
         checkedKeys.unshift.apply(checkedKeys, halfCheckedKeys);
         return checkedKeys;
      },
      /** 根据角色ID查询菜单树结构 */
      getRoleMenuTreeselect(roleId) {
         return roleMenuTreeselect(roleId).then(response => {
            this.menuOptions = response.data.menus;
            return response.data;
         });
      },
      /** 根据角色ID查询部门树结构 */
      getDeptTree(roleId) {
         return deptTreeSelect(roleId).then(response => {
            this.deptOptions = response.data.depts;
            return response.data;
         });
      },
      // 角色状态修改
      handleStatusChange(row) {
         let text = row.status === "0" ? "启用" : "停用";
         this.$modal.confirm('确认要"' + text + '""' + row.code + '"角色吗？').then(function () {
            return changeRoleStatus(row.roleId, row.status);
         }).then(() => {
            this.$modal.msgSuccess(text + "成功");
         }).catch(function () {
            row.status = row.status === "0" ? "1" : "0";
         });
      },
      // 取消按钮
      cancel() {
         this.open = false;
         this.reset();
      },
      // 取消按钮（数据权限）
      cancelDataScope() {
         this.openDataScope = false;
         this.reset();
      },
      // 表单重置
      reset() {
         if (this.$refs.menu != undefined) {
            this.$refs.menu.setCheckedKeys([]);
         }
         this.menuExpand = false,
            this.menuNodeAll = false,
            this.deptExpand = true,
            this.deptNodeAll = false,
            this.form = {
               current: 1,
               size: 10,
               code: undefined,
               name: undefined,
               target: undefined,
               bindStatus: undefined,
               status: undefined,
               startTime: undefined,
               endTime: undefined,
            };
         this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
         this.queryParams.current = 1;
         this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
         this.dateRange = [];
         this.resetForm("queryForm");
         this.handleQuery();
      },
      shipping_addressQuery() {
         this.virtual_customer_list.current = 1;
         this.set_virtual_customer();
      },
      shipping_addressresetQuery() {
         this.shipping_address_data = [];
         this.resetForm("virtual_customer_queryForm");
         this.shipping_addressQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
         this.ids = selection.map(item => item.id)
         this.single = selection.length != 1
         this.multiple = !selection.length
      },
      // 更多操作触发
      handleCommand(command, row) {
         switch (command) {
            case "handleDataScope":
               this.handleDataScope(row);
               break;
            case "handleAuthUser":
               this.handleAuthUser(row);
               break;
            default:
               break;
         }
      },
      // 树权限（展开/折叠）
      handleCheckedTreeExpand(value, type) {
         if (type == 'menu') {
            let treeList = this.menuOptions;
            for (let i = 0; i < treeList.length; i++) {
               this.$refs.menu.store.nodesMap[treeList[i].id].expanded = value;
            }
         } else if (type == 'dept') {
            let treeList = this.deptOptions;
            for (let i = 0; i < treeList.length; i++) {
               this.$refs.dept.store.nodesMap[treeList[i].id].expanded = value;
            }
         }
      },
      // 树权限（全选/全不选）
      handleCheckedTreeNodeAll(value, type) {
         if (type == 'menu') {
            this.$refs.menu.setCheckedNodes(value ? this.menuOptions : []);
         } else if (type == 'dept') {
            this.$refs.dept.setCheckedNodes(value ? this.deptOptions : []);
         }
      },
      // 树权限（父子联动）
      handleCheckedTreeConnect(value, type) {
         if (type == 'menu') {
            this.form.menuCheckStrictly = value ? true : false;
         } else if (type == 'dept') {
            this.form.deptCheckStrictly = value ? true : false;
         }
      },
      /** 新增按钮操作 */
      handleAdd() {
         this.reset();
         this.getMenuTreeselect();
         this.open = true;
         this.title = "添加角色";
      },
      set_virtual_customer() {

         hqDisAddressPage({
            ...this.virtual_customer_list
         }).then((result) => {
            console.log(result);
            this.shipping_address_data = result.data.records
            this.shipping_address_total = result.data.total
         }).catch((err) => {

         });
      },
      //  虚拟客户
      virtualCustomer(row) {
         this.virtual_customer = true
         this.virtual_customer_list = {
            current: 1,
            size: 10,
            disId: row.id,
            code: '',
            consignee: '',
         }
         this.set_virtual_customer()
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
         console.log(row);
         this.reset();
         this.title = "任意接配置";
         this.open = true;
         this.form.disCode = row.code
         // this.reset();
         // const roleId = row.roleId || this.ids
         // const roleMenu = this.getRoleMenuTreeselect(roleId);
         // getRole(roleId).then(response => {
         //   this.form = response.data;
         //   this.open = true;
         //   this.$nextTick(() => {
         //     roleMenu.then(res => {
         //       let checkedKeys = res.checkedKeys
         //       checkedKeys.forEach((v) => {
         //           this.$nextTick(()=>{
         //               this.$refs.menu.setChecked(v, true ,false);
         //           })
         //       })
         //     });
         //   });
         //   this.title = "修改角色";
         // });
      },
      /** 选择角色权限范围触发 */
      dataScopeSelectChange(value) {
         if (value !== '2') {
            this.$refs.dept.setCheckedKeys([]);
         }
      },
      /** 分配数据权限操作 */
      handleDataScope(row) {
         this.reset();
         const deptTreeSelect = this.getDeptTree(row.roleId);
         getRole(row.roleId).then(response => {
            this.form = response.data;
            this.openDataScope = true;
            this.$nextTick(() => {
               deptTreeSelect.then(res => {
                  this.$refs.dept.setCheckedKeys(res.checkedKeys);
               });
            });
            this.title = "分配数据权限";
         });
      },
      /** 分配用户操作 */
      handleAuthUser: function (row) {
         const roleId = row.roleId;
         this.$router.push("/system/role-auth/user/" + roleId);
      },
      /** 提交按钮 */
      submitForm: function () {
         this.$refs["form"].validate(valid => {
            if (valid) {
               if (this.form.disCode != undefined) {
                  // this.form.menuIds = this.getMenuAllCheckedKeys();
                  hqDisSchemeConfigSaveOrUpdate(this.form).then(response => {
                     this.$modal.msgSuccess("操作成功");
                     this.open = false;
                     this.getList();
                  });
               } else {
                  // this.form.menuIds = this.getMenuAllCheckedKeys();
                  // addRole(this.form).then(response => {
                  //   this.$modal.msgSuccess("新增成功");
                  //   this.open = false;
                  //   this.getList();
                  // });
               }
            }
         });
      },
      /** 提交按钮（数据权限） */
      submitDataScope: function () {
         if (this.form.roleId != undefined) {
            this.form.deptIds = this.getDeptAllCheckedKeys();
            dataScope(this.form).then(response => {
               this.$modal.msgSuccess("修改成功");
               this.openDataScope = false;
               this.getList();
            });
         }
      },
      /** 配置按钮操作 */
      handleDelete(row) {
         hqDisConfigList({
            "disId": row.id
         }).then((result) => {
            console.log(result);
            this.resData = result.data
            this.showConfig = true
         }).catch((err) => {

         });
      },
      synchronismData(){
         console.log();
         if (this.ids.length) {
            hqDisIssue(this.ids).then(res=>{
               this.getList()
               this.$message({
                  message: '操作成功',
                  type: 'success'
               });
            })
            
         }else{
            this.$message({
               message: '请先勾选需要操作的数据',
               type: 'warning'
            });
         }
      },
      /** 导出按钮操作 */
      handleExport() {
         this.download('system/role/export', {
            ...this.queryParams
         }, `role_${new Date().getTime()}.xlsx`)
      }
   }
};
</script>